<?php
namespace Admin\Controller;
use Hdphp\Controller\Controller;
class TypeController extends CommonController {
	private $model;
	//连接表
	public function __auto() {
		$this -> model = new \Common\Model\Type;
	}

	//显示列表
	public function index() {
		$typeData = $this -> model -> get();
		View::with('typeData', $typeData);
		View::make();
	}

	//添加方法
	public function add() {
		if (IS_POST) {
			if ($this -> model -> store()) {
				View::success('添加成功', U('Type/index'));
			}
			View::error($this -> model -> getError());
		}
		View::make();
	}

	public function del() {
		$tid = Q('get.tid', 0, 'intval');
		if ($this -> model -> del($tid)) {
			View::success('删除成功', U('Type/index'));
		}
		View::error($this -> model -> getError());
	}

	public function edit() {
		$tid=Q('get.tid',0,'intval');
		$oldData=$this->model->where(array('tid'=>$tid))->find();
		View::with('oldData',$oldData);
		if (IS_POST) {
			if ($this -> model -> edit($tid)) {
//				die;
				View::success('修改成功', U('Type/index'));
			}
//			die;
			View::error($this->model->getError());
		}
		View::make();

	}

}
?>